package tech.yangzhijie.basic.thread;

import java.util.concurrent.TimeUnit;

public class LiftOff implements Runnable {

    private int downCount = 10;
    private static int taskCount = 0;
    private final int id = taskCount++;

    public LiftOff() {
    }

    public LiftOff(int downCount) {
        this.downCount = downCount;
    }

    public String status(){
        return "#"+id+"("+(downCount>0?downCount:"LiftOff")+"),";
    }

    @Override
    public void run() {
        while (downCount-- > 0){
            System.out.println(status());
            //Thread.yield();//暂停当前线程，执行其他线程。
            try {
                //Thread.sleep(100);
                TimeUnit.MILLISECONDS.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
